<?php
/**
 * 物流渠道（基础）
 * (model)
 */

namespace App\Models\Basics;

use Illuminate\Database\Eloquent\Model;
class ExpressChannel extends Model
{
    protected $table = 'b_express_channel';

    public $timestamps = false;

    protected $guarded = [];

    const TRANSPORT_SEA = 1;
    const TRANSPORT_AIR = 2;
    const TRANSPORT_LAND = 3;
    public static $_transport = [
        self::TRANSPORT_SEA  => '海运',
        self::TRANSPORT_AIR  => '空运',
        self::TRANSPORT_LAND => '铁运'
    ];

    //海外仓(谷仓)-运输方式
    //海外仓(谷仓)-运输方式(0:空运 1:海运散货 2:快递 3:铁运整柜 4:海运整柜 5:铁运散货)
    public static $os_transport = [
        self::TRANSPORT_SEA  => 1, //海外仓-海运
        self::TRANSPORT_AIR  => 0, //海外仓-空运
        self::TRANSPORT_LAND => 5  //海外仓-铁运
    ];

    public function area(){
        return $this->belongsTo(SysArea::class,'area_id');
    }

    public static function options($where = []){
        $query = $where ? self::query()->where(formatCondition($where)) : self::query();
        return $query->pluck('name','id');
    }

    public static function existById($id){
        $count = self::query()->where('id',$id)->count();
        return $count > 0 ? true : false;
    }

    public static function getNameById($id){
        return self::query()->where('id',$id)->value('name');
    }

    public static function getIdByName($name){
        return self::query()->where('name',$name)->value('id');
    }

    public static function getModel($id){
        return self::query()->where('id',$id)->first();
    }

}
